package com.ruoyi.web.controller.crm;

import com.bonuo.crm.domain.BuyOrLaboratory;
import com.bonuo.crm.service.BuyOrLaboratoryService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.List;

//已购产品controller
@RestController
@RequestMapping("/crm/buyOrLaboratory")
@Api(tags = "已购产品/实验室现状管理")
public class BuyOrLaboratoryController extends BaseController {
    @Autowired
    private BuyOrLaboratoryService buyOrLaboratoryService;

    //获取已购产品/实验室现状列表
    @ApiOperation(value = "查询已购产品/实验室现状",httpMethod = "GET")
    @GetMapping("/list")
    public TableDataInfo list(BuyOrLaboratory buyProduct,Integer pageNum,Integer pageSize) {
        if(pageNum != null && pageSize != null){
            startPage();
        }
        List<BuyOrLaboratory> buyProductList = buyOrLaboratoryService.selectBuyOrLaboratoryList(buyProduct);
        //查看已购设备/实验室现状 总金额
        BigDecimal amount = buyOrLaboratoryService.selectAmount(buyProduct);
        return getDataTable(buyProductList,amount);
    }

    //添加已购/实验室现状产品
    @ApiOperation(value = "添加已购产品/实验室现状",httpMethod = "POST")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody BuyOrLaboratory buyProduct){
        Integer add = buyOrLaboratoryService.insertBuyOrLaboratory(buyProduct);
        return toAjax(add);
    }

    //删除已购产品/实验室现状
    @ApiOperation(value = "删除已购产品/实验室现状",httpMethod = "DELETE")
    @DeleteMapping("/delete/{id}")
    public AjaxResult delete(@PathVariable Integer id){
        Integer delete = buyOrLaboratoryService.deleteBuyOrLaboratoryById(id);
        return toAjax(delete);
    }

    //修改已购产品/实验室现状
    @ApiOperation(value = "修改已购产品/实验室现状",httpMethod = "PUT")
    @PutMapping("/update")
    public AjaxResult update(@RequestBody BuyOrLaboratory buyProduct){
        Integer update = buyOrLaboratoryService.updateBuyOrLaboratory(buyProduct);
        return toAjax(update);
    }

    //导出已购产品/实验室现状
    @ApiOperation(value = "导出已购产品/实验室现状",httpMethod = "POST")
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuyOrLaboratory buyProduct) {
        List<BuyOrLaboratory> list = buyOrLaboratoryService.selectBuyOrLaboratoryList(buyProduct);
        ExcelUtil<BuyOrLaboratory> util = new ExcelUtil<BuyOrLaboratory>(BuyOrLaboratory.class);
        util.exportExcel(response, list, "已购产品数据");
    }
}
